import {
  createRouter,
  createWebHistory,createWebHashHistory
} from 'vue-router'
import HomeView from '../views/HomeView.vue'

import Layout from "@/layout/index.vue";
import NotFound from '@/layout/NotFound.vue'
const router = createRouter({
  history: createWebHashHistory(),
  routes: [{
      path: '/',
      name: 'layout',
      component: Layout,
      redirect: '/index',
      children: [
        {
          path: '/index',
          name: 'index',
          component: () => import('@/views/Dashboard/index.vue'),
          meta: {
            title: '儀錶盤',
            isLogin: true,
          }
        },

        {
          path: '/student',
          name: 'student',
          component: () => import('@/views/Student/StudentManage/index.vue'),
          meta: {
            title: '學生管理',
            isLogin: true,
          }
        },
        {
          path: '/course',
          name: 'course',
          component: () => import('@/views/Student/CourseManage/index.vue'),
          meta: {
            title: '課程管理',
            isLogin: true,
          }
        },
        {
          path: '/product',
          name: 'product',
          component: () => import('@/views/product/index.vue'),
          meta: {
            title: '產品管理',
            isLogin: true,
          }
        },
        {
          path: '/products',
          name: 'products',
          component: () => import('@/views/products/index.vue'),
          meta: {
            title: '產品組合管理',
            isLogin: true,
          }
        },
        {
          path: '/ticket',
          name: 'ticket',
          component: () => import('@/views/ticket/index.vue'),
          meta: {
            title: '套票管理',
            isLogin: true,
          }
        },


        {
          path: '/about',
          name: 'about',
          component: () => import('../views/AboutView.vue'),
          meta: {
            title: '相关',
            isLogin: true,
          }
        },
        {
          path: '/home',
          name: 'home',
          component: HomeView,
          meta: {
            title: '首页',
            isLogin: true,
          }
        },
        {
          path: '/form',
          name: 'form',
          component: () => import('../views/form/index.vue'),
          meta: {
            title: '表单',
            isLogin: true,
          }
        },
        {
          path: '/table',
          name: 'table',
          component: () => import('../views/table/index.vue'),
          meta: {
            title: '表格',
            isLogin: true,
          }
        },

        {
          path: '/notice',
          name: 'notice',
          component: () => import('@/views/StudentNotice/index.vue'),
          meta: {
            title: '学生公告',
            isLogin: true,
          }
        },
        {
          path: '/teacher',
          name: 'teacher',
          component: () => import('@/views/Set/Teacher/index.vue'),
          meta: {
            title: '職員教師公告',
            isLogin: true,
          }
        },
        {
          path: '/school',
          name: 'school',
          component: () => import('@/views/Set/School/index.vue'),
          meta: {
            title: '學校管理',
            isLogin: true,
          }
        },
        {
          path: '/classroom',
          name: 'classroom',
          component: () => import('@/views/Set/Classroom/index.vue'),
          meta: {
            title: '教室管理',
            isLogin: true,
          }
        },{
          path: '/studentType',
          name: 'studentType',
          component: () => import('@/views/Set/StudentCategory/index.vue'),
          meta: {
            title: '學生類別',
            isLogin: true,
          }
        },
        {
          path: '/number',
          name: 'number',
          component: () => import('@/views/Set/NumberFormat/index.vue'),
          meta: {
            title: '編號格式',
            isLogin: true,
          }
        },{
          path: '/role',
          name: 'role',
          component: () => import('@/views/Set/Menu/index.vue'),
          meta: {
            title: '員工職位及權限',
            isLogin: true,
          }
        },
        {
          path: '/productunit',
          name: 'productunit',
          component: () => import('@/views/Set/productCourses/unit/index.vue'),
          meta: {
            title: '產品單位',
            isLogin: true,
          }
        },
        {
          path: '/producclass',
          name: 'producclass',
          component: () => import('@/views/Set/productCourses/class/index.vue'),
          meta: {
            title: '產品類別',
            isLogin: true,
          }
        },
        {
          path: '/producbrand',
          name: 'producbrand',
          component: () => import('@/views/Set/productCourses/brand/index.vue'),
          meta: {
            title: '產品品牌',
            isLogin: true,
          }
        },
        {
          path: '/producsupplier',
          name: 'producsupplier',
          component: () => import('@/views/Set/productCourses/supplier/index.vue'),
          meta: {
            title: '產品供應商',
            isLogin: true,
          }
        },
        {
          path: '/discount',
          name: 'discount',
          component: () => import('@/views/Set/Collection/discount/index.vue'),
          meta: {
            title: '特別折扣',
            isLogin: true,
          }
        },
        {
          path: '/payment',
          name: 'payment',
          component: () => import('@/views/Set/Collection/payment/index.vue'),
          meta: {
            title: '付款方式',
            isLogin: true,
          }
        },
        {
          path: '/expenditure',
          name: 'expenditure',
          component: () => import('@/views/Set/Collection/expenditure/index.vue'),
          meta: {
            title: '支出項目',
            isLogin: true,
          }
        },
        {
          path: '/remark',
          name: 'remark',
          component: () => import('@/views/Set/Collection/remark/index.vue'),
          meta: {
            title: '收款備註',
            isLogin: true,
          }
        },
        {
          path: '/buyereading',
          name: 'buyereading',
          component: () => import('@/views/Set/Collection/buyereading/index.vue'),
          meta: {
            title: '客戶須知',
            isLogin: true,
          }
        },
        {
          path: '/presuppose',
          name: 'presuppose',
          component: () => import('@/views/Set/Collection/presuppose/index.vue'),
          meta: {
            title: '預設學生',
            isLogin: true,
          }
        },
        {
          path: '/invoice',
          name: 'invoice',
          component: () => import('@/views/Invoices/invoice/index.vue'),
          meta: {
            title: '發票',
            isLogin: true,
          }
        },
        {
          path: '/gathering',
          name: 'gathering',
          component: () => import('@/views/Invoices/gathering/index.vue'),
          meta: {
            title: '收款',
            isLogin: true,
          }
        },
        {
          path: '/refund',
          name: 'refund',
          component: () => import('@/views/Invoices/refund/index.vue'),
          meta: {
            title: '退款',
            isLogin: true,
          }
        },
        {
          path: '/expend',
          name: 'expend',
          component: () => import('@/views/Invoices/expend/index.vue'),
          meta: {
            title: '支出',
            isLogin: true,
          }
        },
        {
          path: '/warehousing',
          name: 'warehousing',
          component: () => import('@/views/Inventory/warehousing/index.vue'),
          meta: {
            title: '入倉',
            isLogin: true,
          }
        },
        {
          path: '/toke',
          name: 'toke',
          component: () => import('@/views/Inventory/toke/index.vue'),
          meta: {
            title: '出倉',
            isLogin: true,
          }
        },
        {
          path: '/rolltoke',
          name: 'rolltoke',
          component: () => import('@/views/Inventory/rolltoke/index.vue'),
          meta: {
            title: '轉倉',
            isLogin: true,
          }
        },
        {
          path: '/Inventorying',
          name: 'Inventorying',
          component: () => import('@/views/Inventory/Inventorying/index.vue'),
          meta: {
            title: '點倉',
            isLogin: true,
          }
        },
        {
          path: '/hireticket',
          name: 'hireticket',
          component: () => import('@/views/hireticket/index.vue'),
          meta: {
            title: '套票使用',
            isLogin: true,
          }
        },
        {
          path: '/time',
          name: 'time',
          component: () => import('@/views/time/index.vue'),
          meta: {
            title: '時間表',
            isLogin: true,
          }
        },
            {
      path: '/studentexcel',
      name: 'studentexcel',
      component: () => import('@/views/Report/basic/studentexcel.vue'),
      meta: {
        title: '學生資料報表',
        isLogin: true,
      }
    },
    {
      path: '/supplierexcel',
      name: 'supplierexcel',
      component: () => import('@/views/Report/basic/supplierexcel.vue'),
      meta: {
        title: '供應商資料報表',
        isLogin: true,
      }
    },
    {
      path: '/productexcel',
      name: 'productexcel',
      component: () => import('@/views/Report/basic/productexcel.vue'),
      meta: {
        title: '產品資料報表',
        isLogin: true,
      }
      },
    {
      path: '/invoiceexcel',
      name: 'invoiceexcel',
      component: () => import('@/views/Report/sale/invoiceexcel.vue'),
      meta: {
        title: '發票報表',
        isLogin: true,
      }
      },
    {
      path: '/gatheringexcel',
      name: 'gatheringexcel',
      component: () => import('@/views/Report/sale/gatheringexcel.vue'),
      meta: {
        title: '收款報表',
        isLogin: true,
      }
      },
      {
        path: '/refundexcel',
        name: 'refundexcel',
        component: () => import('@/views/Report/sale/refundexcel.vue'),
        meta: {
          title: '退款報表',
          isLogin: true,
        }
        },
      {
        path: '/invoiceproexcel',
        name: 'invoiceproexcel',
        component: () => import('@/views/Report/sale/invoiceproexcel.vue'),
        meta: {
          title: '發票項目報表',
          isLogin: true,
        }
        },
      {
        path: '/gatheringexcelpro',
        name: 'gatheringexcelpro',
        component: () => import('@/views/Report/sale/gatheringexcelpro.vue'),
        meta: {
          title: '收款項目報表',
          isLogin: true,
        }
        },
      {
        path: '/refundexcelpro',
        name: 'refundexcelpro',
        component: () => import('@/views/Report/sale/refundexcelpro.vue'),
        meta: {
          title: '發票項目報表',
          isLogin: true,
        }
        },
      {
        path: '/expendexcel',
        name: 'expendexcel',
        component: () => import('@/views/Report/expendexcel.vue'),
        meta: {
          title: '支出報表',
          isLogin: true,
        }
        },
        {
          path: '/teacherexcel',
          name: 'teacherexcel',
          component: () => import('@/views/Report/teacherexcel.vue'),
          meta: {
            title: '導師上課報表',
            isLogin: true,
          }
          },
      {
        path: '/warehouseexcel',
        name: 'warehouseexcel',
        component: () => import('@/views/Report/inventory/warehouseexcel.vue'),
        meta: {
          title: '貨品庫存量報表',
          isLogin: true,
        }
        },
      {
        path: '/hint',
        name: 'hint',
        component: () => import('@/views/Report/inventory/hint.vue'),
        meta: {
          title: '貨品庫存量不足報表',
          isLogin: true,
        }
        },
      {
        path: '/stockcount',
        name: 'stockcount',
        component: () => import('@/views/Report/inventory/stockcount.vue'),
        meta: {
          title: '貨品庫存量排名報表',
          isLogin: true,
        }
        },
      {
        path: '/consume',
        name: 'consume',
        component: () => import('@/views/Report/analysis/consume.vue'),
        meta: {
          title: '學生消費分析',
          isLogin: true,
        }
        },
      {
        path: '/consumetop',
        name: 'consumetop',
        component: () => import('@/views/Report/analysis/consumetop.vue'),
        meta: {
          title: '學生消費排行',
          isLogin: true,
        }
        },
      {
        path: '/dynamic',
        name: 'dynamic',
        component: () => import('@/views/Report/analysis/dynamic.vue'),
        meta: {
          title: '非活躍學生統計',
          isLogin: true,
        }
        },
      {
        path: '/top',
        name: 'top',
        component: () => import('@/views/Report/analysis/top.vue'),
        meta: {
          title: '課程銷售排行',
          isLogin: true,
        }
        },
      {
        path: '/producttop',
        name: 'producttop',
        component: () => import('@/views/Report/analysis/producttop.vue'),
        meta: {
          title: '產品銷售排行',
          isLogin: true,
        }
        },
      {
        path: '/productgrouptop',
        name: 'productgrouptop',
        component: () => import('@/views/Report/analysis/productgrouptop.vue'),
        meta: {
          title: '產品組合銷售排行',
          isLogin: true,
        }
        },
      {
        path: '/yearcome',
        name: 'yearcome',
        component: () => import('@/views/Report/analysis/yearcome.vue'),
        meta: {
          title: '全年營業總表',
          isLogin: true,
        }
        },
  
      ]
    },
    {
      path: '/studentInfo',
      name: 'studentInfo',
      component: () => import('@/views/StudentInfo/index.vue'),
      meta: {
        isLogin: false,
      }
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login/index.vue'),
      meta: {
        title: 'inline school',
      }
    },
    { //出仓
      path: '/tokePrint',
      name: 'tokePrint',
      component: () => import('@/views/Inventory/toke/print/print.vue'),
    },
    {//入仓
      path: '/warehousingPrint',
      name: 'warehousingPrint',
      component: () => import('@/views/Inventory/warehousing/print/print.vue'),
    },
    {//转仓
      path: '/rolltokePrint',
      name: 'rolltokePrint',
      component: () => import('@/views/Inventory/rolltoke/print/print.vue'),
    },
    {//发票
      path: '/invoicePrint',
      name: 'invoicePrint',
      component: () => import('@/views/Invoices/invoice/print/print.vue'),
    },
    {//收款
      path: '/gatheringPrint',
      name: 'gatheringPrint',
      component: () => import('@/views/Invoices/gathering/print/print.vue'),
    },
    {//退款
      path: '/refundPrint',
      name: 'refundPrint',
      component: () => import('@/views/Invoices/refund/print/print.vue'),
    },

    {
      path: '/customer_report_print',
      name: 'customer_report_print',
      component: () => import('@/views/customer_report_print/index.vue'),
      meta: {
        title: 'inline',
        isLogin: true,
      }
    },
    {
      path: '/NoPaging_report_print',
      name: 'NoPaging_report_print',
      component: () => import('@/views/customer_report_print/NoPaging.vue'),
      meta: {
        title: 'inline',
        isLogin: true,
      }
    },


    {
      path: '/404',
      name: '404',
      component: NotFound,
    },
    {
      path:"/:pathMatch(.*)*",
      redirect:"/404" 
     //重定向到home页
    },
  ]
})


router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? to.meta.title : import.meta.env.VITE_APP_TITLE;
  let token = sessionStorage.getItem("token")
  if (to.meta.isLogin && !token && to.path !== '/login') {
    next('/login')
  } else {
    next();
  }
});
export default router